{% extends "layout.html" %}
{% block flash %}
<div id="spinning_success" class="row-fluid text-center" style="display:none;">
    <div class="alert alert-info"><img id="img-spinner" src="{{ url_for('static', filename='css/libs/images/loading-icon.gif') }}"/></div>
</div>
{% endblock %}
{% block body %}
<div class="discover">
  <h2>{{title}}</h2>
  <form style="width: -webkit-fill-available;" role="form" method="POST" class="col-md-10 col-lg-6" action="{{ url_for('admin.db_configuration') }}" autocomplete="off">
    <div class="settings-container">
       <input type="hidden" name="csrf_token" value="{{ csrf_token() }}">
       <label style="font-size: 32px; margin-bottom: 3rem; line-height: 1.22; margin-top: 2rem;" for="config_calibre_dir">{{_('Location of Calibre Database (metadata.db file)')}}</label>
       <div style="margin-bottom: 3rem; padding-left: 0;" class="form-group required input-group">
        <input style="background-color: #ffedde33;" type="text" class="form-control" id="config_calibre_dir" name="config_calibre_dir" value="{% if config.config_calibre_dir != None %}{{ config.config_calibre_dir }}{% endif %}" autocomplete="off" readonly>
        <span class="input-group-btn">
          <button type="button" data-toggle="modal" id="calibre_modal_path" data-link="config_calibre_dir" data-filefilter="metadata.db" data-target="#fileModal" id="library_path" class="btn btn-default" disabled>
            <span class="glyphicon glyphicon-folder-open"></span>
          </button>
        </span>
      </div>
      <p style="margin-bottom: 4rem;">
        {{_("CWA is configured so that your Calibre Database (<code>metadata.db</code> file) should always be somewhere in <code>/calibre-library</code>.
        CWA automatically searches whatever directory you've bound to <code>/calibre-library</code> in your docker-compose file for existing Calibre
        Libraries/metadata.db files on start up. If it finds just one existing library, it mounts it automatically, if it find multiple, by default
        it will mount the largest one automatically and if it doesn't find any, it will automatically create and mount a new one. For more details,
        <a href=\"https://github.com/crocodilestick/Calibre-Web-Automated/wiki/Configuration#database-configuration\">see here</a>!") | safe }}
        <br><br>
        {{_("Therefore, when configuring your docker-compose file for CWA, <b>DO NOT CHANGE THE PATHS IN THE VOLUMES SECTION ON THE RIGHT SIDE OF THE COLONS!</b>") | safe }}
        {{_("These paths are internal to CWA only, you can change what they're bind to to your heart's content on the left-hand side but there's no reason to
        change the paths on the right-hand side.<br><br>If you would like your <code>metadata.db</code> file in a different location to the rest of your
        library, use the <b>Separate Book Files from Library Option below and there, enter the path to the rest of the library</b>") | safe }}
        <br><br>
        {{_("E.g. As long as your library's <code>metadata.db</code> file is bound somewhere within <code>/calibre-library</code>, you could bind the dir
        containing the corresponding book files ect. to something like <code>/books</code> and enter <code>/books</code> in the field that pops up below
        once you've checked the <b>Separate Book Files from Library</b> option.") | safe }}
      </p>
      <h1 style="margin-bottom: 4rem; font-size: 32px;">{{_("Split Library Functionality")}}</h1>
        <div class="form-group required">
        <input type="checkbox" id="config_calibre_split" name="config_calibre_split" data-control="split_settings" data-t ="{{ config.config_calibre_split_dir  }}" {% if config.config_calibre_split %}checked{% endif %} >
        <label style="display: inline; padding: 1rem;" for="config_calibre_split">{{_('<b>Separate Book Files from Library</b> - <code>metadata.db</code> file should remain in <code>/calibre-library</code>, however your library files can be wherever you desire') | safe }}</label>
      </div>
      <div data-related="split_settings">
       <div class="form-group required input-group">
        <input type="text" class="form-control" id="config_calibre_split_dir" name="config_calibre_split_dir" value="{% if config.config_calibre_split_dir != None %}{{ config.config_calibre_split_dir }}{% endif %}" autocomplete="off">
        <span class="input-group-btn">
          <button type="button" data-toggle="modal" id="calibre_modal_split_path" data-link="config_calibre_split_dir" data-filefilter="" data-target="#fileModal" id="book_path" class="btn btn-default"><span class="glyphicon glyphicon-folder-open"></span></button>
        </span>
      </div>
      </div>
    {% if feature_support['gdrive'] %}
      <div class="form-group required">
        <input type="checkbox" id="config_use_google_drive" name="config_use_google_drive" data-control="gdrive_settings" {% if config.config_use_google_drive %}checked{% endif %} >
        <label style="padding: 1rem;" for="config_use_google_drive">{{_('Use Google Drive?')}}</label>
      </div>
      {% if not gdriveError and config.config_use_google_drive %}
        {% if show_authenticate_google_drive and config.config_use_google_drive %}
          <div class="form-group required">
            <a href="{{ url_for('gdrive.authenticate_google_drive') }}" id="gdrive_auth" class="btn btn-primary">{{_('Authenticate Google Drive')}}</a>
          </div>
        {% else %}
            {% if not show_authenticate_google_drive %}
            <div class="form-group required">
              <label for="config_google_drive_folder">{{_('Google Drive Calibre folder')}}</label>
              <select name="config_google_drive_folder" id="config_google_drive_folder" class="form-control">
                {%  for gdrivefolder in gdrivefolders %}
                <option value="{{ gdrivefolder.title }}" {% if gdrivefolder.title == config.config_google_drive_folder %}selected{% endif %}>{{ gdrivefolder.title }}</option>
                {% endfor %}
              </select>
            </div>
            {% if config.config_google_drive_watch_changes_response %}
              <label for="config_google_drive_watch_changes_response">{{_('Metadata Watch Channel ID')}}</label>
              <div class="form-group input-group required">
                <input type="text" class="form-control" name="config_google_drive_watch_changes_response" id="config_google_drive_watch_changes_response" value="{{ config.config_google_drive_watch_changes_response['id'] }} expires on {{ config.config_google_drive_watch_changes_response['expiration'] |  strftime }}" autocomplete="off" disabled="">
                <span class="input-group-btn"><a href="{{ url_for('gdrive.revoke_watch_gdrive') }}" id="watch_revoke" class="btn btn-primary">{{_('Revoke')}}</a></span>
              </div>
            {% else %}
              <a href="{{ url_for('gdrive.watch_gdrive') }}" id="enable_gdrive_watch" class="btn btn-primary">Enable watch of metadata.db</a>
            {% endif %}
          {% endif %}
        {% endif %}
      {% endif %}
    {% endif %}
    <div style="display: inline-flex; flex-direction: row; flex-wrap: wrap; align-items: flex-start; gap: 2rem; float: none; margin-bottom: 1rem; padding-left: 0px;" class="col-sm-12">
      <div id="db_submit" name="submit" class="btn btn-default">{{_('Save')}}</div>
      <a href="{{ url_for('admin.admin') }}" id="config_back" class="btn btn-default">{{_('Cancel')}}</a>
    </div>
    </div>
  </form>
</div>
{% endblock %}
{% block modal %}
{{ filechooser_modal() }}
{{ change_confirm_modal() }}
<div id="InvalidDialog" class="modal fade" role="dialog">
  <div class="modal-dialog modal-sm">
    <!-- Modal content-->
    <div class="modal-content">
      <div class="modal-header bg-info"></div>
      <div class="modal-body text-center">
        <p>{{_('New db location is invalid, please enter valid path')}}</p>
          <p></p>
        <button type="button" class="btn btn-default" id="invalid_confirm" data-dismiss="modal">{{_('OK')}}</button>
      </div>
    </div>
  </div>
</div>
{% endblock %}
